package com.mollytask.superadmin;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.mollytask.R;
import com.weigan.loopview.LoopView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by freshxu on 2017/5/24.
 */

public class DataRemindFragment extends Fragment {

    private LoopView mYearloop;

    private Button mDataReviewBtn;

    int year;

    public static DataRemindFragment newInstance() {
        DataRemindFragment myFragment = new DataRemindFragment();
        return myFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_data_remind, container, false);

        mYearloop = (LoopView) view.findViewById(R.id.loopView_year);
        mDataReviewBtn = (Button) view.findViewById(R.id.btn_data_review);
        setListener();
        initLoop();
        return view;
    }


    private void initLoop() {
        List<String> list = new ArrayList<>();
        for (int i = 2017; i >= 2000; i--) {
            list.add(i + "年");
        }
        mYearloop.setItems(list);
    }

    private void setListener() {
        mDataReviewBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                year = 2017 - mYearloop.getSelectedItem();
                Intent intent = new Intent(getActivity(), DataRemindActivity.class);
                intent.putExtra("year", year);
                startActivity(intent);
            }
        });
    }

}
